﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Programacion3_TPFinal_LosBorbotones
{
    public partial class Final : Form
    {
        public Final()
        {
            InitializeComponent();
        }

        Datos obDatos = new Datos();

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = "insert into Alumnos (Dni_Alumno,Nombre_Alumno,Apellido_Alumno,Edad_Alumno,Telefono_Alumno,Telefono2_Alumno,FechaIngreso_Alumno) values (" + this.textBox1.Text + ",'" + this.textBox2.Text + "','" + this.textBox3.Text + "'," + this.textBox4.Text + ",'" + this.textBox5.Text + "','" + this.textBox6.Text + "',getdate())";
            if (obDatos.insertar(sql)) { MessageBox.Show("Registro Insertado"); } else { MessageBox.Show("Error al insertar"); }
            Application.Restart();
                
            
        }

        private void Final_Load(object sender, EventArgs e)
        {
            obDatos.consultar("select * from Alumnos", "Alumnos");
            this.dataGridView1.DataSource = obDatos.ds.Tables["Alumnos"];
            this.dataGridView1.Refresh();

            this.listBox1.DataSource = obDatos.consultar2("Alumnos");
            this.listBox1.DisplayMember="Nombre_Alumno";
            this.listBox1.ValueMember = "Dni_Alumno";
            this.listBox1.Refresh();

            this.comboBox1.DataSource = obDatos.consultar2("Alumnos");
            this.comboBox1.DisplayMember = "Nombre_Alumno";
            this.comboBox1.ValueMember = "Dni_Alumno";
            this.comboBox1.Refresh();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (obDatos.eliminar("Alumnos", "Dni_Alumno=" + this.listBox1.SelectedValue.ToString() + "")) { MessageBox.Show("Registro eliminado correctamente"); } else { MessageBox.Show("Error al eliminar el registro"); }
            Application.Restart();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string campos = "Dni_Alumno=" + this.textBox7.Text + ", Nombre_Alumno='" + this.textBox8.Text + "', Apellido_Alumno='" + this.textBox9.Text + "', Edad_Alumno=" + this.textBox10.Text + ", Telefono_Alumno='" + this.textBox11.Text + "', Telefono2_Alumno='" + this.textBox12.Text + "', FechaIngreso_Alumno= getdate()";
            if (obDatos.actualizar("Alumnos", campos,"Dni_Alumno=" + this.comboBox1.SelectedValue.ToString() + "")) { MessageBox.Show("Registro Actualizado"); } else { MessageBox.Show("Error al intentar Actualizar"); }
            Application.Restart();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

      
    }
}
